<?php
class Register extends CI_Controller {
    
    public function __construct(){
        parent::__construct();

         $this->load->helper(array("url","date","utility_helper"));

    }
	public function index()
	{

            $temp['title'] = 'Tuyển dụng và đào tạo';
			$temp['template'] = 'frontend/dangky/index';
         	$this->load->view("frontend/_layout/default", $temp);
	}

public function checkexitsEmail()
{
 

        $this->load->Model("Mregister");
        if($this->Mregister-> checkEmail($_POST['email'])){
            echo "email có thể sử dụng";   
                  
        }
        else{
             echo "email tồn tại";
        }
  
}
	public function addInfo()
    {
       
        if(isset($_POST['full_name']) && $_POST['full_name'] !="")
        {

           $salt = create_random_string(5);
                $add = array(
                    "username" => $this->input->post("full_name"),
                    "password"  => md5($this->input->post("password")),
                    "salt"      => $salt,
                    "email"     => $this->input->post("txtemail"),
                    "level"     => 2, // mac dinh la memmber khi dang ki thanh vien
                    "add_date"  => date("Y-m-d H:i:s"),
                    "active"    => 1, // chua kich hoat
                 );
            $flag = TRUE;
            if($flag==TRUE){
                //--- Gui mail kich hoat neu add thanh cong
                $message = "";
                $this->load->Model("Mregister");
                if($this->Mregister->addUser($add)){

                  /*  $userid = mysql_insert_id();
                    $link_active = base_url()."home/user/active/?userid=".$userid."&key=".md5($salt);
                    $message  = "Please follow this link to active your acount <br/>".
                    $message .= "Link : <a href=".$link_active.">".$link_active."</a><br/>";
                    $message .= "username : ".$add['username']."<br/>";
                    $message .= "password : ".$this->input->post("password");

                    $mail = array(
                            "to_receiver"   => $add['email'],
                            "message"       => $message,
                        );

                    $this->load->library("my_email");
                    $this->my_email->config($mail);
                    $this->my_email->sendmail();

                    $this->session->set_userdata(array($this->_register => TRUE));
                    redirect(base_url()."home/user/register_complete");*/
                }
            }


         }      

    }
}